<template>
  <div class="basicInformation">
    <div class="title">门店列表</div>
    <div class="operation">
      <div class="operationLeft">
        <el-input class="inline-input" v-model="userSearchModel.name" @input="nameSearch" placeholder="请输入姓名"
          style="width:220px"></el-input>

        <el-input class="inline-input" v-model="userSearchModel.phone" @input="mobileSearch" placeholder="请输入手机号"
          style="width:220px"></el-input>
        <el-button @click="dialogFormVisible = true">添加门店</el-button>
      </div>
    </div>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="门店名称" prop="name" width="200" fixed> </el-table-column>
      <el-table-column label="门店地址" prop="address" width="400"> </el-table-column>
      <el-table-column label="营业执照" prop="businessLicense" width="200">
        <template slot-scope="scope">
          <img :src="scope.row.businessLicense" class="businessLicense">
        </template>
      </el-table-column>
      <el-table-column label="门店照片" prop="imgUrl" width="200">
        <template slot-scope="scope">
          <img :src="scope.row.imgUrl.split(',')[0]" class="businessLicense">
        </template>
      </el-table-column>
      <el-table-column label="球桌数量" prop="tablesNum" width="100"> </el-table-column>
      <el-table-column label="营业时间" prop="businessHours" width="150"> </el-table-column>
      <el-table-column label="押金" prop="deposit" width="100"> </el-table-column>
      <el-table-column label="签约人信息" prop="signatory" width="150"> </el-table-column>
      <el-table-column label="身份证号" prop="idNumber" width="300"> </el-table-column>
      <el-table-column label="手机号" prop="phone" width="200"> </el-table-column>
      <el-table-column label="操作" width="200">
        <template slot-scope="scope">
          <el-button type="text" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
          <el-button type="text" @click="dialogFormVisible = true">编辑</el-button>
          <el-button type="text" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="this.currentPage"
      :page-sizes="[10, 20, 30, 40]" :page-size="this.pageSize" layout="total, sizes, prev, pager, next, jumper"
      :total="this.total" background class="turnPage">
    </el-pagination>

    <el-dialog title="添加门店" :visible.sync="dialogFormVisible">
      <el-form :model="form" label-position="right" label-width="80px">
        <el-form-item label="门店名称">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="门店地址">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="营业执照">
          <el-upload class="avatar-uploader" action="https://jsonplaceholder.typicode.com/posts/" :show-file-list="false"
            :on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
            <img v-if="form.imageUrl" :src="form.imageUrl" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="签约人信息">
          <el-input v-model="form.price"></el-input>
        </el-form-item>
        <el-form-item label="身份证号">
          <el-input v-model="form.integral"></el-input>
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model="form.integral"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="addStore">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getStoreList, addStore, delCoach, editCoach } from "@/api/getData";
export default {
  name: "UsetList",
  data() {
    return {
      userSearchModel: {
        name: '',
        phone: ''
      },
      tableData: [],
      total: 0,
      currentPage: 1,
      pageSize: 10,
      dialogFormVisible: false,
      form: {
        name: "测试",
        tablesNum: 12,
        longitude: 123,
        latitude: 123,
        businessHours: "06:00 - 24:00",
        province: "天津",
        provinceid: 2,
        city: "滨海区",
        cityid: 78,
        county: "阿诗丹顿",
        countyid: 296,
        address: "天津市xxxxxxxxxx路",
        businessLicense: "/upfile/2022-06/",
        signatory: "签约人",
        idNumber: "2255522525252",
        phone: "13525252525",
        imgUrl:"/upfile/2022-06/"
      }
    };
  },

  methods: {
    //添加门店
    addStore() {
      addStore(this.form).then((res) => {
        if (res.code == 0) {
          this.$message.success('添加成功');
          this.dialogFormVisible = false
        } else {
          this.$message.error('添加失败');
        }
      });
    },
    //输入后匹配
    nameSearch(val) {
      this.userSearchModel.name = val
      this.getStoreList()
    },
    mobileSearch(val) {
      this.userSearchModel.phone = val
      this.getStoreList()
    },
    handleAvatarSuccess(res, file) {
      this.form.imageUrl = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isLt2M;
    },
    handleEdit(index, row) {
      this.$router.push({
        path: "/shop-detail",
        query: { shopId: row.id },
      });
    },
    handleDelete(index, row) {
      this.$confirm("确认删除该患者吗?", "删除确认", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
      });
    },
    handleSizeChange(val) {
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
    },
    //教练列表
    getStoreList() {
      const params = {
        name: this.userSearchModel.name,
        phone: this.userSearchModel.phone,
        currentPage: this.currentPage,
        pageSize: this.pageSize
      };
      getStoreList(params).then((res) => {
        this.tableData = res.data.list
        this.total = res.data.total
      });
    }
  },
  mounted() {
    this.getStoreList()
  },
};
</script>

<style lang="scss" scoped>
.accountList-dialog ::v-deep {
  .el-dialog {
    width: 30%;
    max-width: 368px;
    border-radius: 10px;
    overflow: hidden;

    .el-dialog__header {
      padding: 0;
      height: 50px;
      text-align: center;
      background: #ededed;

      .el-dialog__title {
        font-size: 18px;
        color: #8e8e8e;
        line-height: 50px;
      }
    }

    .el-dialog__body {
      padding: 0 60px;

      >div {
        display: flex;
        margin-top: 30px;

        label {
          width: 60px;
          line-height: 44px;
          font-size: 18px;
        }

        .el-input__inner {
          height: 44px;
          width: 100%;
          font-size: 18px;
        }

        .el-select {
          width: 100%;
          margin: 0;
          font-size: 18px;
        }
      }
    }

    .el-dialog__footer {
      text-align: center;
      border-top: 1px solid #ededed;
      margin-top: 30px;
      padding: 30px 0;

      .el-button {
        width: 98px;
      }
    }
  }
}

.basicInformation {
  padding: 0 56px;

  .businessLicense {
    width: 140px;
    height: 140px;
  }

  .avatar {
    width: 200px;
  }

  .el-icon-plus {
    border: 1px solid #DCDFE6;
    font-size: 50px;
    color: #DCDFE6;
  }

  .title {
    font-size: 20px;
    color: #3c3c3c;
    margin: 40px 0;
  }

  .operation {
    display: flex;
    justify-content: space-between;
    margin: 20px 0;

    .operationLeft {
      .el-input {
        margin-right: 20px;
      }
    }

    .operationBtn {
      width: 128px;
      height: 39px;
      background: #24bbd3;
      color: #fff;
      font-size: 18px;
      padding: 0;
    }
  }

  .turnPage {
    text-align: right;
    margin-top: 20px;
  }

  .el-table::v-deep {

    thead th:first-child,
    tbody td:first-child {
      padding-left: 40px;
    }
  }
}</style>